#!/usr/bin/python

from pymongo import MongoClient
import os

client = MongoClient()
db = client['tut']
c = db['codenames']

fin = open("codenames", "r")
lines = fin.read().splitlines(True)
fin.close()


if not os.path.isdir("static"):
    os.mkdir("static")

c.drop()
for line in lines:
    (version, nickname) = line.rstrip().split(":")
    if not os.path.isdir(version):
        print("run fun.py first")
    else:
        c.insert_one({"version":version, "nickname":nickname, "files":os.listdir(version)})
        os.rename(version, "static/" + version)
